import type { CommonResult } from "../../dto";


export function success() : CommonResult<null> {
    return successWithData(null)
}

export function successWithData<T>(data: T) : CommonResult<T> {
    return successWithMsgAndData("成功",data);
}

export function successWithMsgAndData<T>(msg:string,data:T) : CommonResult<T> {
    const commonResult: CommonResult<T> = {
        code: 200,
        data: data,
        msg
    };
    return commonResult;
}

export function errorWithMsg<T>(msg:string) : CommonResult<T> {
    return errorWithCodeAndMsg(500,msg);
}

export function errorWithCodeAndMsg<T>(code:number,msg:string) : CommonResult<T> {
    const commonResult: CommonResult<T> = {
        code,
        data: null,
        msg
    };
    return commonResult;
}